package com.seecen.controller;

import com.seecen.pojo.Address;
import com.seecen.service.AddressService;
import com.seecen.until.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/Address")
@CrossOrigin
public class AddressController {

    @Autowired
    private AddressService addressService;

    @PostMapping("/findAllAddress")
    public Result findHeadlineByHid(Long id) {
        Result result = addressService.findAllAddress(id);
        return result;
    }

    @PostMapping("/addMoney")
    public Result addMoney(@RequestParam("id")long id, @RequestParam("amount")int money ) {
        Result result = addressService.addMoney(id,money);
        return result;
    }

    // 更新数据
    @PostMapping("/updateAddress")
    public Result updateAddress(@RequestBody Address address) {
        System.out.println("接收参数: " + address);
        Result result = addressService.updateAddress(address);
        return result;
    }
    // 删除数据
    @PostMapping("/deleteAddress")
    public Result deleteAddress(@RequestParam("id")long id) {
        System.out.println("接收参数: " + id);
        Result result = addressService.deleteAddress(id);
        return result;
    }
    // 添加地址
    @PostMapping("/addAddress")
    public Result addAddress(@RequestBody Address address) {
        System.out.println("接收参数: " + address);
        Result result = addressService.addAddress(address);
        return result;
    }
}
